import * as R from 'ramda';

import { Button, Popconfirm } from 'antd';

import React from 'react';
import { useRequest } from 'ahooks';

const ConfirmButton = ({
  confirmProps,
  text,
  service,
  buttonProps,
  onSuccess,
}) => {
  const { run, loading } = useRequest(service, { manual: true, onSuccess });
  return (
    <Popconfirm
      onConfirm={run}
      okButtonProps={{ loading }}
      {...R.omit(['onConfirm', 'okButtonProps'], confirmProps)}
    >
      <Button {...buttonProps}>{text}</Button>
    </Popconfirm>
  );
};

export default React.memo(ConfirmButton);
